<!DOCTYPE html>
<html>
<head>
    <title>添加公众号文章</title>
    {% include 'admin/common/header.html' %}
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item">
                    <label class="layui-form-label">公众号</label>
                    <div class="layui-input-block">
<!--                        <input type="text" name="wx_group_code" lay-verify="title" autocomplete="off" placeholder="请输入公众号分组"-->
<!--                               class="layui-input">-->
                         <select id="wx_name" name="wx_name" lay-verify="required" lay-filter="wx_name">
<!--                                <option value="">&#45;&#45;请选择&#45;&#45;</option>-->
                            </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" id="article_title" name="article_title" lay-verify="article_title" autocomplete="off" placeholder="请输入文章标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接</label>
                    <div class="layui-input-block">
                        <input type="text" id="article_url" name="article_url" lay-verify="article_url" autocomplete="off" placeholder="请输入文章URL"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">发布时间</label>
                    <div class="layui-input-block">
                     <input class="layui-input" id="article_time" name="article_time" type="text" placeholder="yyyy">
                    </div>
                </div>


            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="Article-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'admin/common/footer.html' %}
<script>


  layui.use(['form', 'jquery'], function () {
    let form = layui.form
    let $ = layui.jquery
    let laydate = layui.laydate;
    laydate.render({
    elem: '#article_time'
    ,type: 'datetime'
     });

    //渲染公众号分组下拉选择框
    $.ajax({
            url: "/admin/wxOfficialAcc/getOffAcc",
            type : "GET",
            contentType: "application/json;charset=utf-8",
            dataType : "json",
            success:function(data) {
                    // 此处每次打开 做一次清空操作，防止记忆上次的选择
                    $("#wx_name").empty();
                    // 此处添加默认的选择(如果没有这个option，则ios系统可能无法打开下拉框，所以为了(照顾)他们，此处还是有必要的)
                    $("#wx_name").append("<option value='' selected disabled>" +"----请选择----"+"</option>")
                    for (var i = 0; i < data.data.length; i++) {
                        $("#wx_name").append("<option value=" + data.data[i].wx_name  + ">" +data.data[i].wx_name +"</option>")
                    }
                    // 注意 没有这个渲染，可能会回填失败
                    layui.form.render('select');
            }
        })

    form.on('submit(Article-save)', function (data) {

      $.ajax({
        url: '/admin/wxOfficialAcc/article/save',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
              parent.layui.table.reload('user-table')
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        }
      })
      return false
    })
  })
</script>
<script>
</script>
</body>
</html>